package com.youxuan.controller;

import com.youxuan.pojo.entity.RequestParam;
import com.youxuan.pojo.entity.ResponseFormat;
import com.youxuan.pojo.entity.ResponseResult;
import com.youxuan.pojo.entity.User;
import com.youxuan.service.UserService;
import com.youxuan.util.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public ResponseResult<ResponseFormat.LoginFormat> login(@RequestBody RequestParam.LoginParam user){
        return userService.login(new User(user.getPhonenumber(),user.getPassword()));
    }

    @ApiOperation("登出")
    @PostMapping("/logout")
    public ResponseResult logout(){
        return userService.logout();
    }

    @ApiOperation("修改密码")
    @PutMapping("/updatePassword")
    public ResponseResult updatePassword(@RequestBody RequestParam.UpdatePasswordParam param){
        return userService.updatePassword(param.getOldPassword(),param.getNewPassword());
    } 

}
